import React from 'react'
import { connect } from 'react-redux'
import ImageDetail from '../components/ImageDetail'
import Favorite from '../components/Favorite'
import { odooActionCreators } from '../redux'

const mapStateToProps = (state) => ({
  favorites: new Set(state.odoo.userInfo.favorite_ids.image),
  likes: new Set(state.odoo.userInfo.like_ids.image)
})

const mapDispatchToProps = (dispatch) => ({
  onFavoritePress: (data, isFavorited) => {
    const tag = 'pic'
    const level = 'favorite'
    if (isFavorited) {
      dispatch(odooActionCreators.delFavoritePost(data.id, tag, level))
    } else {
      dispatch(odooActionCreators.favoritePost(data, tag, level))
    }
  },
  onLikePress: (data, isLiked) => {
    const tag = 'pic'
    const level = 'like'
    if (isLiked) {
      dispatch(odooActionCreators.delFavoritePost(data.id, tag, level))
    } else {
      dispatch(odooActionCreators.favoritePost(data, tag, level))
    }
  }
})

// {data, favorites, likes, onFavoritePress, onLikePress}
const _ImageDetail = (props) => {
  return (
    <Favorite
      {...props}
      Component={ImageDetail}
    />
  )
}

export default connect(mapStateToProps, mapDispatchToProps)(_ImageDetail)
